//============================================================================
// Name        : Jav.cpp
// Author      : Michah Lerner
// Version     :
// Copyright   : Free for anyone
// Description : Hello World in C++, Ansi-style
//============================================================================
//
//-Winline -finline-functions  -finline-limit=64578
//-c -fmessage-length=0 -fno-non-lvalue-assign -Weffc++ -Wabi -Wold-style-cast -Woverloaded-virtual -Wsign-promo
//
//
#include <iostream>
#include "Clocker.h"
#include "Board.h"
#include "Dictionary.h"
#include "Scrabble.h"
#include "Common.h"
using namespace std;

string boardName;
string dictName;

static char ** processArgs(char **arg, char **lastArg) {
	while (arg < lastArg) {
		if (strcmp(*arg, "-h") == 0) {
			cout << "help" << endl;
			return NULL;
		}
		if (strcmp(*arg, "-d") == 0) {
			arg++;
			dictName = string(*arg++);
			continue;
		}
		if (strcmp(*arg, "-b") == 0) {
			arg++;
			boardName = string(*arg++);
			continue;
		}
		break;
	}
	return arg;
}

int main(int argc, char **argv) {
	Clocker clock;
#ifdef _USE_HASH_TABLE_
	cout << "\nUsing USE_HASH_TABLE dictionary" << endl;
#else
	cout << "\nUsing set dictionary" << endl;
#endif
	char **nextArg = processArgs(argv + 1, argv + argc);
	if (dictName.length() == 0) {
		cerr << "Missing: -d <dictionary>" << endl;
		return -1;
	}
	if (boardName.length() == 0) {
		cerr << "Missing: -b <board>" << endl;
	}

	if (nextArg >= argv + argc) {
		cout << "No rack given; cannot proceed. " << endl;
		return -1;
	}

	string rack(*(nextArg++));
	Board board(boardName);
	Dictionary dictionary(dictName);
	Scrabble *scrabble = new Scrabble(dictionary, board, rack);
	cout << clock.readAndReset() << endl;
	scrabble->initCellChars();

	cout << "Invoking evalAll()" << endl;
	scrabble->evalAll();
	cout << "Invoking evalAllCostly()" << endl;
	scrabble->evalAllCostly(); // Depreciated
	cout << "Invoking evalMost()" << endl;
	scrabble->evalMost();      // Depreciated

	cout << clock.readAndReset() << endl;

#ifdef _USE_HASH_TABLE_
	cout << "Used USE_HASH_TABLE dictionary" << endl;
#else
	cout << "Used set dictionary" << endl;
#endif
	return 0;
}
